<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2018/5/22
 * Time: 0:01
 */

namespace app\common;


use app\common\model\User;

class Author
{
    static $author = [];
    private  $uid = 0;

    /**
     * @param $id
     * @return User|bool|mixed|null
     * @throws \think\exception\DbException
     */
    function get($id){
        if(isset(self::$author[$id])){
            return self::$author[$id];
        }
        return $this->queryUser();
    }

    /**
     * @return User|bool|null
     * @throws \think\exception\DbException
     */
    private function queryUser()
    {
        if($info = User::get($this->uid)){
            self::$author[$this->uid] = $info;
            return $info;
        }
        return false;
    }
}